var mapIds = [867233050, 867233100, 867233150, 867233200, 867233250, 867233300, 867233350, 867233400, 867233450, 867233500, 867233550, 867233600];
var 准备地图 = 867233000;

function init() {}

function setup(c, a) {
    em.setProperty("state", 1);
    em.setProperty("leader", "true");
    var c = em.newInstance("副本_莫奈德_Act3_城堡守卫战");
    for (var b = 0; b < mapIds.length; b++) {
        var d = c.setInstanceMap(mapIds[b]);
        d.resetFully();
        d.killAllMonsters(false)
    }
    return c
}

function onPlayerRegistered(b, a) {
    a.setReviveCount(-100);
    var c = b.getMapInstance(0);
    a.changeMap(c, c.getPortal(0));
    b.startEventTimer(30 * 60 * 1000)
}

function onPlayerRevived(b, a) {
    var c = a.getMap();
    a.eventRevive();
    a.forceRevive();
    a.getAPI().playerMessage(-1, "在亚皮纳斯的祝福下复活，恢复了全部的体力。");
    a.getAPI().addPopupSay(9400584, 1000, "#face0#亚皮纳斯的祝福与你同在……", "", 0);
    return true
}

function onMapChanged(c, b, a) {
    if (mapIds.indexOf(a) < 0) {
        on玩家退场(c, b, false);
        return
    }
    if (a == 867236100) {
        c.startEventTimer(30 * 60 * 1000);
        if (b.getAPI().isLeader()) {
            c.schedule("go1", 60 * 1000);
            c.schedule("go2", 120 * 1000);
            c.schedule("go3", 160 * 1000)
        }
    }
    em.setProperty("kill", "0");
    em.setProperty("clear", "0");
    em.setProperty("curMap", a)
}

function go1() {
    em.getPlayersInMap(867236100).forEach(function (a) {
        a.getAPI().openNpc(74, "莫奈德_延时任务");
        a.scheduleOpenNpcTask(5, 75, "莫奈德_延时任务")
    })
}

function go2() {
    em.getPlayersInMap(867236100).forEach(function (a) {
        a.getAPI().openNpc(76, "莫奈德_延时任务");
        a.scheduleOpenNpcTask(5, 77, "莫奈德_延时任务")
    })
}

function go3() {
    em.getPlayersInMap(867236100).forEach(function (a) {
        a.getAPI().openNpc(78, "莫奈德_延时任务");
        a.scheduleOpenNpcTask(5, 79, "莫奈德_延时任务")
    })
}

function onPlayerDisconnected(b, a) {
    on玩家退场(b, a, false);
    return 0
}

function onTimeOut(a) {
    a.getPlayers().forEach(function (b) {
        on玩家退场(a, b, true)
    })
}

function onMonsterKilled(a, b) {
    a.getPlayers().forEach(function (e) {
        var d = em.getNumberProperty("kill") + 1;
        em.setProperty("kill", d);
        var c = e.getMapId();
        if (c == 867233100) {
            if (b == 9402252) {
                e.updateInfoQuest(64002, "man=135;stage=1;enemy=4;man0=0;man1=0;companion=1");
                e.updateInfoQuest(64003, "enemy0=0;enemy1=1;companion0=0;man0=35;companion1=8;man1=128;map0=0;map1=0");
                e.changeMap(867233150, 0)
            }
        } else {
            if (c == 867233200) {
                if (b == 9402250) {
                    e.updateInfoQuest(64001, "dir1=0;man=557;stage=1;enemy=21053;seq=1;mine=0;Fidx=0;companion=3726514;dir0=0");
                    e.updateInfoQuest(64002, "man=56;stage=2;enemy=0;man0=0;man1=0;companion=2");
                    e.updateInfoQuest(64003, "enemy0=2;enemy1=1;companion0=3;man0=47;companion1=7;man1=128;map0=1;map1=1");
                    e.changeMap(867233250, 0)
                }
            } else {
                if (c == 867233300) {
                    if (b == 9402249) {
                        e.updateInfoQuest(64001, "dir1=1;man=382;stage=2;enemy=5213;seq=1;mine=0;Fidx=0;companion=26514;dir0=0");
                        e.updateInfoQuest(64002, "man=53;stage=3;enemy=2;man0=0;man1=0;companion=6");
                        e.updateInfoQuest(64003, "enemy0=5;enemy1=1;companion0=2;man0=56;companion1=5;man1=28;map0=2;map1=2");
                        e.changeMap(867233350, 0)
                    }
                } else {
                    if (c == 867233400) {
                        if (b == 9402251) {
                            e.updateInfoQuest(64001, "dir1=1;man=298;stage=3;enemy=513;seq=1;mine=0;Fidx=0;companion=146;dir0=0");
                            e.updateInfoQuest(64002, "man=42;stage=4;enemy=1;man0=0;man1=0;companion=4");
                            e.updateInfoQuest(64003, "enemy0=5;enemy1=3;companion0=1;man0=135;companion1=6;man1=53;map0=3;map1=3");
                            e.changeMap(867233450, 0)
                        }
                    } else {
                        if (c == 867233500) {
                            if (d == 7) {
                                e.updateInfoQuest(64001, "dir1=1;man=110;stage=4;enemy=513;seq=1;mine=0;Fidx=0;companion=146;dir0=0");
                                e.updateInfoQuest(64002, "man=42;stage=5;enemy=5;man0=0;man1=0;companion=4");
                                e.updateInfoQuest(64003, "enemy0=5;enemy1=3;companion0=1;man0=135;companion1=6;man1=53;map0=4;map1=4");
                                e.changeMap(867233550, 0)
                            }
                        } else {
                            if (c == 867233600) {
                                if (d == 6) {
                                    e.updateInfoQuest(64001, "dir1=1;man=42;stage=5;enemy=513;seq=1;mine=0;Fidx=0;companion=146;dir0=0");
                                    e.updateInfoQuest(64002, "man=42;stage=6;enemy=3;man0=0;man1=0;companion=9");
                                    e.updateInfoQuest(64003, "enemy0=5;enemy1=3;companion0=1;man0=135;companion1=6;man1=53;map0=5;map1=5");
                                    e.changeMap(867233001, 0)
                                }
                            }
                        }
                    }
                }
            }
        }
    });
    return 1
}

function onPartyDisbanded(a) {}

function onPlayerKilled(b, a) {}
var setupTask;

function randomNum(b, a) {
    switch (arguments.length) {
        case 1:
            return parseInt(Math.random() * b + 1, 10);
            break;
        case 2:
            return parseInt(Math.random() * (a - b + 1) + b, 10);
            break;
        default:
            return 0;
            break
    }
}

function initProp(a, b) {
    if (em.getProperty(a) == null) {
        em.setProperty(a, b)
    }
}

function initPropArray(a, d, c, e) {
    for (var b = c; b <= e; b++) {
        if (em.getProperty(a + "_" + b) == null) {
            em.setProperty(a + "_" + b, d)
        }
    }
}

function on玩家退场(c, b, a) {
    b.getAPI().teachSkill(80011562, -1, 0);
    b.getAPI().teachSkill(80011565, -1, 0);
    b.getAPI().teachSkill(80011561, -1, 0);
    b.getAPI().teachSkill(80011567, -1, 0);
    b.getAPI().teachSkill(80011641, -1, 0);
    c.disposeIfPlayerBelow(a ? 999 : 0, 准备地图);
    em.getProperties().clear();
    em.setProperty("state", 0);
    em.setProperty("leader", "true");
    c.unregisterPlayer(b)
}

function onItemPickedUp(b, a, c) {};